package com.msh.automatic.android.control.util.api

import android.content.Context
import android.os.Build
import com.alibaba.fastjson2.JSONObject
import com.msh.automatic.android.control.service.AIAccessibilityService
import com.msh.automatic.android.control.util.DeviceUtil

object DeviceApi {

    fun register(id:String):Triple<String,String,JSONObject?>{
        return BaseApi.post("/p/device/register",
            mapOf(
                "id" to id,
                "model" to Build.MODEL,
                "brand" to Build.BRAND,
                "device" to Build.DEVICE,
                "manufacturer" to Build.MANUFACTURER,
                "release" to Build.VERSION.RELEASE,
                "sdkInt" to Build.VERSION.SDK_INT,
                )
        )
    }

    fun activation(id:String,activationCode:String):Triple<String,String,JSONObject?>{
        return BaseApi.post("/p/device/activation",
            mapOf(
                "id" to id,
                "activationCode" to activationCode,
            )
        )
    }
    fun heartbeat(currentTaskLogId:String?,context: Context):Triple<String,String,JSONObject?>{
        return BaseApi.post("/d/device/heartbeat",
            mapOf(
                "accessibility" to DeviceUtil.isAccessibilityServiceEnabled(context,
                    AIAccessibilityService::class.java),
                "power" to DeviceUtil.isIgnoringBatteryOptimizations(context),
                "fileManager" to DeviceUtil.isStoragePermissions(),
                "currentTaskLogId" to currentTaskLogId,
                "installApk" to DeviceUtil.isInstallApk(context),
                "controlAppVersion" to DeviceUtil.getVersionCode(context)
            )
        )
    }

}